package com.xyh.student.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xyh.student.entity.Library;
import com.xyh.student.entity.ResponseData;
import com.xyh.student.service.LibraryService;

@RestController
@RequestMapping("/library")
public class LibraryController {
    
    @Autowired
    private LibraryService libraryService;

    //新建题库library{id,name}
    @PostMapping("/insert")
    public ResponseData insert(Library library){
        System.out.println(library);
        return libraryService.insertLibrary(library);
    }

    //查询所有题库
    @GetMapping("/all")
    public ResponseData findAll(){
        return libraryService.findAllLibrary();
    }

    //查询某个题库的所有题目，传入题库id
    @GetMapping("/find/{lid}")
    public ResponseData findQuestion(@PathVariable("lid") int lid){
        return libraryService.findQuestion(lid);
    }

    //查询某个题库的所有题目，传入题库id
    @GetMapping("/findLib/{id}")
    public ResponseData findById(@PathVariable("id") int id){
        return libraryService.findById(id);
    }

    //删除题库传入题库ID
    @PostMapping("/delete/{id}")
    public ResponseData deleteById(@PathVariable("id") int id){
        return libraryService.deleteById(id);
    }
}

